/**
 * Copyright [2019] [LiBo/Alex of copyright liboware@gmail.com ]
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.hyts.algorithm.zijie;

import com.hyts.algorithm.Solution;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

/**
 * @project-name:coffice-toolbox
 * @package-name:com.hyts.algorithm.zijie
 * @author:LiBo/Alex
 * @create-date:2019-11-02 07:24
 * @copyright:libo-alex4java
 * @email:liboware@gmail.com
 * @description:
 */
public class day01 implements Solution {


    @Test
    @Override
    public void solution1() {

        int n = 5;

        Integer [][] testArray = {{1,2},{5,3},{4,6},{7,5},{9,0}/*,{10,2}*/};

        List<String> sortedList = new LinkedList<>();

        for(int i = 0 ; i< testArray.length ; i++){
            for(int j = 0 ; j< testArray.length-i-1 ; j++){
                if(testArray[j][0]<testArray[j+1][0]){
                    Integer []  tempArray = testArray[j];
                    testArray[j] = testArray[j+1];
                    testArray[j+1] = tempArray;
                }
            }
        }

        /**
            int maxYValue = testArray[0][1];
            for(Integer [] elements:testArray){
                if(maxYValue<elements[1]){
                    maxYValue = elements[1];
                    System.out.println(elements[0]+","+elements[1]);
                }
            }
        */

        for(int i = 0;i<testArray.length;i++){
            int x = testArray[i][0];
            int y = testArray[i][1];
            if( i == 0  || y>testArray[i-1][1]){
                ((LinkedList<String>) sortedList).addFirst(x+","+y);
            }
        }
        System.out.println(sortedList);
    }

    @Test
    @Override
    public void solution2() {

        /*int[][] testArrays = {{1,23,45,1},{3,18,36,1},{1,41,19,1},{6,23,13,1,15}};

        List<String> resultList = new LinkedList<>();

        int currentMaxValue = 0;


        for(int [] elements : testArrays){
            int solutionValue = 1;
            for(int element:elements){
                solutionValue *=element;
            }
            System.out.println(solutionValue+" -> "+Arrays.toString(elements));
            if(currentMaxValue < solutionValue){
                currentMaxValue = solutionValue;
                resultList.clear();
                resultList.add(Arrays.toString(elements));
            }else if(currentMaxValue == solutionValue){
                resultList.add(Arrays.toString(elements));
            }
        }
        System.out.println(resultList);*/

    }

    @Test
    @Override
    public void solution3() {
        int start = 0;

        int end = 50;

        boolean flag = true;

        for(int i = start ; i<=50; i++){

            for(int j = 0; j<(int) Math.sqrt(i) && flag ; j++){

                if( i % j == 0 && i != j){
                    flag = false;
                }

            }
            System.out.println(i);
        }
    }
}
